package com.ruoyi.book.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.github.pagehelper.PageHelper;
import org.springframework.security.access.prepost.PreAuthorize; // 保留引用
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.book.domain.BookInstitutionInfo;
import com.ruoyi.book.service.IBookInstitutionInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 机构信息Controller
 *
 * @author hd
 * @date 2025-03-31
 */
@RestController
@RequestMapping("/book/institutions")
@Api(tags = "机构信息管理")
public class BookInstitutionInfoController extends BaseController {
    @Autowired(required = false)
    private IBookInstitutionInfoService bookInstitutionInfoService;

    /**
     * 查询机构信息列表
     */
    @ApiOperation("查询机构信息列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bookInstitutionInfo",value = "查询条件对象（如机构ID、名称等）",required = false,paramType = "query",dataType = "BookInstitutionInfo")
    })
    // 注释权限控制
    // @PreAuthorize("@ss.hasPermi('book:institutions:list')")
    @GetMapping("/list")
    public TableDataInfo list(BookInstitutionInfo bookInstitutionInfo,Integer pageNum,Integer pageSize)
    {
        if(pageNum!=null&&pageSize!=null){
            PageHelper.startPage(pageNum,pageSize);
        }else{
            startPage();
        }
        List<BookInstitutionInfo> list = bookInstitutionInfoService.selectBookInstitutionInfoList(bookInstitutionInfo);
        return getDataTable(list);
    }

    /**
     * 导出机构信息列表
     */
    @ApiOperation("导出机构信息列表为Excel文件")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bookInstitutionInfo",value = "查询条件对象（如机构ID、名称等）",required = false,paramType = "query",dataType = "BookInstitutionInfo")
    })
    // 注释权限控制
    // @PreAuthorize("@ss.hasPermi('book:institutions:export')")
    @Log(title = "机构信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response,BookInstitutionInfo bookInstitutionInfo) {
        List<BookInstitutionInfo> list = bookInstitutionInfoService.selectBookInstitutionInfoList(bookInstitutionInfo);
        ExcelUtil<BookInstitutionInfo> util = new ExcelUtil<>(BookInstitutionInfo.class);
        util.exportExcel(response, list, "机构信息数据");
    }

    /**
     * 获取机构信息详细信息
     */
    @ApiOperation("获取机构信息详细信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "institutionId",value = "机构ID",required = true,paramType = "path",dataType = "Long",example = "123")
    })
    // 注释权限控制
    // @PreAuthorize("@ss.hasPermi('book:institutions:query')")
    @GetMapping("/{institutionId}")
    public AjaxResult getInfo(
            @PathVariable("institutionId") Long institutionId
    ) {
        return success(bookInstitutionInfoService.selectBookInstitutionInfoByInstitutionId(institutionId));
    }

    /**
     * 新增机构信息
     */
    @ApiOperation("新增机构信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bookInstitutionInfo",value = "机构信息",required = true,paramType = "body",dataType = "BookInstitutionInfo")
    })
    @Log(title = "机构信息", businessType = BusinessType.INSERT)
    // 注释权限控制
    // @PreAuthorize("@ss.hasPermi('book:institutions:add')")
    @PostMapping
    public AjaxResult add(@RequestBody BookInstitutionInfo bookInstitutionInfo) {
        return toAjax(bookInstitutionInfoService.insertBookInstitutionInfo(bookInstitutionInfo));
    }

    /**
     * 修改机构信息
     */
    @ApiOperation("修改机构信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bookInstitutionInfo",value = "机构信息",required = true,paramType = "body",dataType = "BookInstitutionInfo")
    })
    @Log(title = "机构信息", businessType = BusinessType.UPDATE)
    // 注释权限控制
    // @PreAuthorize("@ss.hasPermi('book:institutions:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody BookInstitutionInfo bookInstitutionInfo) {
        return toAjax(bookInstitutionInfoService.updateBookInstitutionInfo(bookInstitutionInfo));
    }

    /**
     * 删除机构信息
     */
    @ApiOperation("删除机构信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "institutionIds",value = "机构ID数组（如：1,2,3）",required = true,paramType = "path",dataType = "Long[]",example = "1,2,3")
    })
    @Log(title = "机构信息", businessType = BusinessType.DELETE)
    // 注释权限控制
    // @PreAuthorize("@ss.hasPermi('book:institutions:remove')")
    @DeleteMapping("/{institutionIds}")
    public AjaxResult remove(@PathVariable Long[] institutionIds) {
        return toAjax(bookInstitutionInfoService.deleteBookInstitutionInfoByInstitutionIds(institutionIds));
    }
}